% Remember to use the lgrind style

\Head{}
\File{equals.txt}{2007}{10}{29}{12:58}{2098}
\index{equalNumbersFirst}\Proc{equalNumbersFirst}\L{\LB{\K{static}_\V{WICOutput}_\V{equalNumbersFirst}(\V{WICInput}_\V{inputData})\{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\V{SolutionGenerator}_\V{sl}_=_\K{new}_\V{SolutionGenerator}();}}
\L{\LB{}\Tab{4}{\K{int}[\,]_\V{ySet}_=_\V{inputData}.\V{getYSet}().\V{clone}();_}}
\L{\LB{}\Tab{4}{\V{Vector}\<\K{int}[\,]\>_\V{solution}_=_\K{new}_\V{Vector}\<\K{int}[\,]\>();}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\V{Hashtable}\<\V{Integer},_\V{QElement}\>_\V{htable}_=_\K{null};}}
\L{\LB{}\Tab{4}{\V{QElement}_\V{temp}_=_\K{null};}}
\L{\LB{}\Tab{4}{\V{PriorityQueue}\<\V{QElement}\>_\V{pq}_=_\K{null};}}
\L{\LB{}\Tab{4}{\V{HashSet}\<\K{int}[\,]\>_\V{ts}_=_\K{null};}}
\L{\LB{}\Tab{4}{\K{int}_\V{status}_=_\N{0};}}
\L{\LB{}\Tab{4}{\K{int}[\,]_\V{interval};}}
\L{\LB{}\Tab{4}{\K{int}_\V{a},\V{b},\V{c};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{while}(\K{true})\{}}
\L{\LB{}\Tab{8}{\K{switch}(\V{status})\{}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{case}_\N{0}\V{:}_\C{}//_scan_the_input_sequence\CE{}}}
\L{\LB{}\Tab{12}{\V{htable}_=_\V{findMultiplicities}(\V{ySet},_\V{sl});}}
\L{\LB{}\Tab{12}{\K{if}(\V{htable}.\V{size}()_==_\N{0})\C{}//_we_are_done,_only_0s\CE{}}}
\L{\LB{}\Tab{16}{\K{return}_\K{new}_\V{WICOutput}(\V{solution},_\V{solution}.\V{size}());}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{pq}_=_\K{new}_\V{PriorityQueue}\<\V{QElement}\>(\V{htable}.\V{size}(),_\V{sl}.\K{new}_\V{Comp}());}}
\L{\LB{}\Tab{12}{\V{pq}.\V{addAll}(\V{htable}.\V{values}());}}
\L{\LB{}\Tab{12}{\V{status}_=_\N{1};}}
\L{\LB{}\Tab{12}{\K{break};}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{8}{\K{case}_\N{1}\V{:}_\C{}//extract_elements_from_the_queue_and_find_the_intervals\CE{}}}
\L{\LB{}\Tab{12}{\K{if}(\V{pq}.\V{size}()_==_\N{0})}}
\L{\LB{}\Tab{16}{\K{return}_\K{new}_\V{WICOutput}(\V{solution},_\V{solution}.\V{size}());}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{temp}_=_\V{pq}.\V{peek}();}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{if}(\V{temp}.\V{getMultiplicity}()_==_\N{1})\{}}
\L{\LB{}\Tab{16}{\V{status}_=_\N{2};}}
\L{\LB{}\Tab{16}{\K{break};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{pq}.\V{poll}();_\C{}//_Let{'}s_throw_away_the_first_element_now}\Tab{72}{\CE{}}}
\L{\LB{}}
\L{\LB{}\Tab{12}{\C{}//here_we_get_the_intervals\CE{}}}
\L{\LB{}\Tab{12}{\V{ts}_=_\V{findIntervals}(\V{ySet},\V{temp}.\V{getFirstOccurence}(),\V{temp}.\V{getMultiplicity}()\-\N{1},\V{temp}.\V{getY}());}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{if}(\V{ts}.\V{size}()_==_\N{0}_\&\&_\V{pq}.\V{size}()_!=_\N{0})\C{}//empty_set_:(\CE{}}}
\L{\LB{}\Tab{16}{;\C{}//let{'}s_try_our_luck_with_the_next_QElement\CE{}}}
\L{\LB{}\Tab{12}{\K{else}_\K{if}(\V{ts}.\V{size}()_==_\N{0}_\&\&_\V{pq}.\V{size}()_==_\N{0})\{}}
\L{\LB{}\Tab{16}{\V{status}_=_\N{2};}}
\L{\LB{}\Tab{16}{\K{break};}}
\L{\LB{}\Tab{12}{\}}\Tab{32}{}}
\L{\LB{}\Tab{12}{\K{else}\{}}
\L{\LB{}\Tab{16}{\V{Iterator}\<\K{int}[\,]\>_\V{iter}_=_\V{ts}.\V{iterator}();}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\K{while}(\V{iter}.\V{hasNext}())\{}}
\L{\LB{}\Tab{28}{}}
\L{\LB{}\Tab{20}{\V{interval}_=_\V{iter}.\V{next}();}}
\L{\LB{}\Tab{20}{\V{a}_=_\V{interval}[\N{0}];}}
\L{\LB{}\Tab{20}{\V{b}_=_\V{interval}[\N{1}];}}
\L{\LB{}\Tab{20}{\V{c}_=_\V{temp}.\V{getY}();}}
\L{\LB{}\Tab{28}{}}
\L{\LB{}\Tab{20}{\C{}//update_the_values_covered_by_the_intervals\CE{}}}
\L{\LB{}\Tab{20}{\K{for}(\K{int}_\V{i}=\V{a};_\V{i}\<=\V{b};_\V{i}++)}}
\L{\LB{}\Tab{24}{\V{ySet}[\V{i}]_=_\V{ySet}[\V{i}]_\-_\V{c};}}
\L{\LB{}\Tab{20}{}}
\L{\LB{}\Tab{20}{\C{}//add_the_triple_to_the_solution_set._Adjust_the_values_too\CE{}}}
\L{\LB{}\Tab{20}{\V{solution}.\V{add}(\K{new}_\K{int}[\,]\{\V{a}+\N{1},\V{b}+\N{2},\V{c}\});}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\V{status}_=_\N{0};_\C{}//let{'}s_go_back_to_regenerate_the_data\CE{}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{break};}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{case}_\N{2}\V{:}_\C{}//_pass_the_control_to_generateSolutionMin()\CE{}}}
\L{\LB{}\Tab{12}{\V{WICOutput}_\V{partialSol}_=_}}
\L{\LB{}\Tab{20}{\V{generateSolutionMin}(\K{new}_\V{WICInput}(\V{inputData}.\V{getN}(),_\V{inputData}.\V{getK}(),_\V{ySet}));}}
\L{\LB{}\Tab{12}{\V{solution}.\V{addAll}(\V{partialSol}.\V{getData}());}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{WICOutput}(\V{solution},\V{solution}.\V{size}());}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{\}}}
